package com.mall.service.order.controller;

import com.mall.autoconfig.temple.OssTemplate;
import com.mall.commons.common.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/aliyun")
public class OssController {
    @Autowired(required = false)
    private OssTemplate ossTemplate;

    //图片上传
    @PostMapping("/oss/upload")
    public CommonResult<Map<String ,String>> uploadOss(MultipartFile photoFile) throws IOException {
        String originalFilename = photoFile.getOriginalFilename();
        InputStream inputStream = photoFile.getInputStream();
        String url = ossTemplate.upload(originalFilename, inputStream);
        Map<String ,String> map = new HashMap<>();
        map.put("url",url);
        return CommonResult.success(map);

    }
}
